<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<div th:replace="pages/admin/commons/header :: header"></div>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
<style>
    .cen {
        text-align: center !important;
    }
</style>
<body>
<div class="wap-container">
    <nav class="breadcrumb" style="background-color:#fff;padding: 0 24px">
        首页
        <span class="c-gray en">/</span>
        儿童保健
        <span class="c-gray en">/</span>
        保健短信知识库
        <a class="btn btn-success radius f-r" href="javascript:location.replace(location.href);"
           style="line-height:1.6em;margin-top:3px" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>
    <article class="Hui-admin-content clearfix">
        <div class="wap-container">
            <div class="panel">
                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                    <legend>保健短信知识库</legend>

                    <a style="float: right; margin-right: 5%" href="javascript:;" id="add_record"
                       class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加数据</a>
                    <div style="width: 250px;margin-left: 35%" th:if="${result} == null"
                         class="form-controls col-xs-8 col-sm-9">
                        <span class="select-box">
							<select id="sel2" class="select" name="category">
							</select>
                        </span>
                    </div>
                </fieldset>

                <div style="display: inline-block; width: 68%; height: 410px; padding: 10px; border: 1px solid #ddd; overflow: auto;margin-left: 15%">

                    <table style="float: right;" class="layui-table">
                        <colgroup>
                            <col width="150">
                            <col width="200">
                            <col>
                        </colgroup>
                        <thead style="text-align: center">
                        <tr>
                            <th class="cen" colspan="2">年龄</th>
                            <th class="cen" rowspan="2">月龄</th>
                            <th class="cen" rowspan="2">序号</th>
                            <th class="cen" rowspan="2">停用</th>
                            <th class="cen" rowspan="2">操作</th>
                        </tr>
                        <tr>
                            <th class="cen">岁</th>
                            <th class="cen">个月</th>
                        </tr>
                        </thead>
                        <tbody id="nodeInfo">

                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <!--				<td class="va-t"><iframe ID="testIframe" Name="testIframe" FRAMEBORDER=0 SCROLLING=AUTO width=100%  height=390px SRC="product-category-add.html"></iframe></td>-->
    </article>
</div>
<!--_footer 作为公共模版分离出去-->
<div th:replace="pages/admin/commons/footer :: footer"></div>
<script th:src="@{/layui/layui.js}" charset="utf-8"></script>
<script type="text/javascript">

    $(function () {

        var add_record_node = '';
        $.ajax({
            url: "/childhealth/childrenDxzsk/findChildrenDxzskParent",
            method: "POST",
            success: function (result) {
                $.each(result.data, function (index, item) {
                    var op1 = $("<option value='" + item.id + "'></option>").append(item.information);
                    $("#sel2").append(op1);
                })
                var x = $($("#sel2").find("option").get(0)).val();
                add_record_node = x;
                getDetail(x);

            }
        })

        $("#sel2").change(function () {
            add_record_node = $(this).val();
            getDetail($(this).val());
        })

        function getDetail(id) {
            $.ajax({
                url: "/childhealth/childrenDxzsk/getChildrenStandardDetail/" + id,
                method: "POST",
                success: function (result) {
                    console.log(result);

                    $('#nodeInfo').empty();
                    var node = result.data;
                    $.each(node, function (index, item) {
                        var tdYear = $("<td  class='cen x'></td>").append(item.year);
                        var tdMonth = $("<td class='cen x'></td>").append(item.month);
                        var tdMonthAge = $("<td class='cen x'></td>").append(item.monthAge);
                        var tdOrderNumber = $("<td class='cen x'></td>").append(item.orderNumber);
                        var tdDetail = $("<td style='display: none' class='cen'></td>").append(item.detail);
                        if (item.isOpen == 1) {
                            var tdIsOpen = $("<td class='cen x'></td>").append("<input disabled checked type='checkbox'>")
                        } else {
                            var tdIsOpen = $("<td class='cen x'></td>").append("<input disabled type='checkbox'>")
                        }

                        //
                        // var tdIsOpen = $("<td class='cen'></td>").append(item.isOpen);

                        var tdOther = $("<td></td>").append(
                            "<button uniqueId=" + item.id + " class=\"btn btn-danger radius delBtn\" type=\"button\"><i class=\"Hui-iconfont\"></i > 删除 </button>" +
                            "&nbsp;&nbsp;" +
                            "<button uniqueId=" + item.id + " class=\"btn btn-success radius updBtn\" type=\"button\"><i class=\"Hui-iconfont\"></i > 修改 </button>");
                        $("<tr></tr>").append(tdYear).append(tdDetail).append(tdMonth).append(tdMonthAge).append(tdOrderNumber).append(tdIsOpen).append(tdOther).appendTo("#nodeInfo");
                    });


                    $(".x").on('click', function () {
                        layer.alert($($($(this).parent()).find("td").get(1)).text());
                    })

                    //删除
                    $(".delBtn").on('click', function () {
                        var uniqueId = $(this).attr("uniqueId");
                        layer.confirm('是否确定删除: ' + $(this).parent().parent().find('td').eq(1).text() + ' ？', {
                            btn: ['删除', '取消'] //按钮
                        }, function () {
                            layer.msg('删除成功！', {icon: 1});
                            setInterval(function () {
                                window.location.href = "/childhealth/childrenDxzsk/data-del?id=" + uniqueId;
                            }, 1000)
                        });


                    })

                    //修改
                    $(".updBtn").on('click', function () {
                        member_add('修改', '/childhealth/childrenDxzsk/data-upd?type=toUpd&nodeId=' + $(this).attr("uniqueId"), '', '510')
                    })
                }
            })
        }


        //添加记录
        $("#add_record").click(function () {
            member_add('添加', '/childhealth/childrenDxzsk/data-upd?type=toAdd&addRecordNode=' +
                add_record_node, '', '510'
            )
        })
    })

</script>
</body>
</html>
